import axios from '../../axios/index'

export interface menuOperate {
    alwaysShow?: number //聚合子路由: 1是 0否（前端）
    component?: string
    componentName?: string
    icon?: string
    id?: string
    isLeaf?: number //是否是子节点: 1:是 0:不是
    isRoute?: number //是否路由菜单: 0:不是 1:是（默认值1）（前端）
    name?: string
    parentId?: string
    permsUrl?: string
    redirect?: string
    sortNo?: number
    type?: number //类型(0菜单，1按钮，2接口)
    url?: string
    routePath?: string
}

//创建菜单
export const createMenu = (data: menuOperate) => {
    return axios({
        method: 'post',
        url: '/api/user/manage/permissions',
        data
    })
}

//删除菜单
export const deleteMenu = (id: string) => {
    return axios({
        method: 'delete',
        url: '/api/user/manage/permissions',
        params: {
            id
        }
    })
}

//编辑菜单
export const updateMenu = (data: menuOperate) => {
    return axios({
        method: 'put',
        url: '/api/user/manage/permissions',
        data
    })
}

//菜单启用禁用
export const menuDisable = (id: string, disable: number) => {
    return axios({
        method: 'post',
        url: '/api/user/manage/permissions/status',
        data: {
            id,
            disable
        }
    })
}

//获取菜单
export const menuTree = () => {
    return axios({
        method: 'get',
        url: '/api/user/manage/permissions/tree'
    })
}

//获取用户拥有的权限
export const userMenuTree = () => {
    return axios({
        method: 'get',
        url: '/api/user/manage/permissions/user-tree'
    })
}
